package lc20240423;

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

//华为机试 HJ20
public class PasswordCheck {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        while (scanner.hasNextLine()) {
            String s = scanner.nextLine();
            System.out.println(checkPw(s));
        }
    }
    public static String checkPw(String s){
        if (s.length()<=8)
            return "NG";
        int count=0;
        if (s.matches(".*[a-z].*")){
            count++;
        }
        if (s.matches(".*[A-Z].*")){
            count++;
        }
        if (s.matches(".*\\d.*")){
            count++;
        }
        if (s.matches(".*[\\W_].*")){
            count++;
        }
        if (count<3)
            return "NG";
        Set<String> set=new HashSet<>();
        for (int i = 0; i <s.length() - 1; i++) {
            for (int j = i + 3; j <= s.length() ; j++) {
               String sub=s.substring(i,j);
               if (set.contains(sub)){
                   return "NG";
               }
               set.add(sub);
            }
        }
        return "OK";
    }
}
